/**
 * Licensed under the Apache License Version 2.0.
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package net.interknit.knitter.cg.view;

import net.interknit.knitter.cg.layout.CollectionElement;
import net.interknit.knitter.cg.layout.LayoutElement;
import net.interknit.knitter.cg.model.JavaType;
import net.interknit.knitter.cg.util.ReflectionHelper;
import net.interknit.knitter.fw.types.Any;
import net.interknit.knitter.fw.types.AnyCollection;

/**
 *
 */
public class AnyCollectionTypeView extends JavaTypeView
{
	public AnyCollectionTypeView(JavaType javaType)
	{
		super(javaType);
	}

	@Override
	protected String[] getAdditionalPlaceholders()
	{
		return new String[] {
			"STATE_GENERIC_1_DECLARATION",
			"STATE_GENERIC_1_NAME",
		};
	}

	@Override
	public LayoutElement getLayoutElement()
	{
		return new CollectionElement(this);
	}

	@Override
	public String ADAPTER_DECLARATION()
	{
		return AnyCollection.class.getName();
	}

	@Override
	public String ADAPTER_INSTANTIATION()
	{
		return AnyCollection.class.getName();
	}

	@Override
	public String UNWRAP_CLAUSE()
	{
		return ".unwrap(" + ReflectionHelper.getConcreteClassName(getJavaType().getTypeClass()) + ".class)";
	}

	public String STATE_GENERIC_1_DECLARATION()
	{
		return Any.class.getName();
	}

	public String STATE_GENERIC_1_NAME()
	{
		return Any.class.getName();
	}

	static boolean isAnyCollectionTypeView(JavaType javaType)
	{
		boolean anyCollection = false;
		if(! javaType.getGenericJavaTypes().isEmpty())
		{
			anyCollection = javaType.getGenericJavaTypes().get(0).getTypeClass().equals(Object.class);
		}
		else if(! javaType.getDerivedGenericJavaTypes().isEmpty())
		{
			anyCollection = javaType.getDerivedGenericJavaTypes().get(0).getTypeClass().equals(Object.class);
		}

		return anyCollection;
	}
}
